package com.example.testrss;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.net.URL;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;

import android.os.Bundle;
import android.app.Activity;
import android.graphics.Bitmap;
import android.util.Log;
import android.view.Menu;
import android.widget.ImageView;
import android.widget.TextView;

public class MainActivity extends Activity {

	// Test for Git
	private static String GIT = "my fisrt test Git";
	private static String GIT2 = "my second test Git";
	
	private static String LOG_TAG = "Test_RSS";
	
	private static String RSS_URL = "http://www.nasa.gov/rss/dyn/image_of_the_day.rss";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		// final IotdHandler handler = new IotdHandler();
		// new Thread() {
		// public void run() {
		// handler.proceedFeed();
		// }
		// }.start();
		//
		// resetDisplay(handler.getTitle(), handler.getDate(),
		// handler.getImage(), handler.getDescription());

		try {
			
			InputStream inputStream =
					getApplicationContext().getAssets().open("image_of_the_day.xml");
			InputSource inputSource = new InputSource(inputStream);
			inputSource.setEncoding("utf-8");
			
			XMLParser_Nasa handler = new XMLParser_Nasa();

			SAXParserFactory factory = SAXParserFactory.newInstance();
			SAXParser parser = factory.newSAXParser();
			XMLReader reader = parser.getXMLReader();
			reader.setContentHandler(handler);

			reader.parse(inputSource);

		} catch (ParserConfigurationException e) {
			Log.e(LOG_TAG, "ParserConfigurationException");
		} catch (SAXException e) {
			Log.e(LOG_TAG, "SAXException");
		} catch (IOException e) {
			Log.e(LOG_TAG, "IOException");
		} // try-catch

	} // onCreate()

	private void resetDisplay(String title, String date, Bitmap image,
			StringBuffer description) {
		TextView titleView = (TextView) findViewById(R.id.imageTitle);
		titleView.setText(title);

		TextView dateView = (TextView) findViewById(R.id.imageDate);
		dateView.setText(date);

		ImageView imageView = (ImageView) findViewById(R.id.imageView1);
		imageView.setImageBitmap(image);

		TextView descriptionView = (TextView) findViewById(R.id.imageDescription);
		descriptionView.setText(description);

	} // resetDisplay()

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
